package cn.openea.perpartner.growth.service.impl;

import cn.openea.perpartner.growth.entity.GrowthRecord;
import cn.openea.perpartner.growth.mapper.GrowthRecordMapper;
import cn.openea.perpartner.growth.service.IGrowthRecordService;
import cn.openea.perpartner.growth.service.IGrowthUserGradeService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * (GrowthRecord)表服务实现类
 *
 * @author makejava
 * @since 2022-08-09 11:13:27
 */
@Service("growthRecordService")
public class GrowthRecordServiceImpl extends ServiceImpl<GrowthRecordMapper, GrowthRecord> implements IGrowthRecordService {
    @Autowired
    IGrowthUserGradeService gradeService;
    @Transactional(rollbackFor = {RuntimeException.class, Error.class})
    @Override
    public boolean add(GrowthRecord record) {
        record.setType("add");
        gradeService.update(record.getUserid(),record.getScore());
        return save(record);
    }
    @Override
    public List<GrowthRecord> selectList(String userId) {
        LambdaQueryWrapper<GrowthRecord> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(GrowthRecord::getUserid,userId);
        wrapper.orderByDesc(GrowthRecord::getCreateTime);
        return baseMapper.selectList(wrapper);
    }
}

